*** One-Child Policy, Marriage Distortion, and Welfare Loss ***
*** by Wei Huang, Yinghao Pan and Yi Zhou ***

clear all 
set more off
set scheme s1color
cap log close 
graph set window fontface "Times New Roman"

set niceness 10
gl MAIN = "F:\Dropbox"

gl path1 = "$MAIN/Census"
gl path2 = "$MAIN/Marriage/Working_data"
gl path3 = "$MAIN/Marriage/Restat/dataverse_files/Results" 
gl path4 = "$MAIN/Marriage/Restat/dataverse_files/Graphics" 



use "$path2/unmarried", clear
keep if relation == 0 | relation == 1 | relation == 2 | relation == 6 

merge 1:1 wave area hhid name relation using "$path2/min_marr_policy", keepusing(marry_1 marry_2 marry_3)


drop if mi(hktype)
replace urban = hktype == 1 
su age 

cap gen female = 1-male
cap gen han = 1- minority 
replace unmarried = unmarried * 100 
foreach n in 25 30 35 40 45 {
gen unmarr_`n' = marr_age > `n' if !mi(marr_age)
replace unmarr_`n' = 1 if unmarried == 100 & age > `n'
replace unmarr_`n' = unmarr_`n' *100 
}
gen urban_hk = hktype == 2 

egen clsid = group(prov_hk year_birth)

gen marry_9 = unmarried == 0 & (mi(marry_1) & mi(marry_2) & mi( marry_3))

recode marry_1 marry_2 marry_3 (. = 0) 

gen HH = marry_1 * 100 
gen HM = marry_2 * 100 
gen MM = marry_3 * 100 
gen Other = marry_9 * 100 
gen HOMO = HH + MM
su HOMO

keep if age <= 55 
keep if age > 25
keep if year_birth <= 1980 
keep if Other == 0 



**** Figure 4(a) ****


preserve
keep if year_birth >= 1970 & year_birth <= 1979
keep if han == 1 
cap gen treat = 1 if prov == 11 | prov == 13 | prov == 21 | prov == 31 | prov == 32 | prov == 33 | prov == 35 ///
|prov == 41 | prov == 42 | prov == 43 |prov == 44 | prov == 45| prov == 46| prov == 53| prov == 64 | prov == 65
replace treat = 0 if mi(treat)

gen age_group = age > 30 & age < 36
replace age_group = 2 if age > 35

collapse unmarried [aw=aw], by( age_group treat )
reshape wide unmarried , i(age_group) j(treat)
gen dif = unmarried1- unmarried0 
sort age_group
loc i = string(dif, "%9.3f")
gen n = age_group
replace n = n - 2 if age_group == 1
sort n
loc i1 = string(dif, "%9.3f")
sort dif
loc i2 = string(dif, "%9.3f")
graph bar unmarried0 unmarried1  , ylabel(0(5)20) bargap(1) over(age_group, gap(100)  relabel(1 "Ages 26-30" 2 "Ages 31-35" 3 "Ages 36-40"))    legend(rows(2) lab(2 "Provinces w/ fines increase in 1989-1995") lab(1 "Provinces w/o fines increase in 1989-1995")) ytit("Unmarried (%)")    blabel(bar,format(%9.3f) ) text(19.5 12 "Difference = `i'") text(10 50 "Difference = `i1'") text(6.5 85 "Difference = `i2'") scheme(s1mono)
gr export "$path4/unmarried_agegrp_han.pdf",replace 

restore 

**** Figure 4(b) ****


preserve
keep if year_birth >= 1970 & year_birth <= 1979
keep if han == 1 
cap gen treat = 1 if prov == 11 | prov == 13 | prov == 21 | prov == 31 | prov == 32 | prov == 33 | prov == 35 ///
|prov == 41 | prov == 42 | prov == 43 |prov == 44 | prov == 45| prov == 46| prov == 53| prov == 64 | prov == 65
replace treat = 0 if mi(treat)
drop if treat == . 
levelsof age
qui:{
foreach x of numlist `r(levels)' {

ttest unmarried if age==`x' ,by(treat)
replace se=r(se) if age==`x'
}
}


collapse unmarried se[aw=aw], by( age treat )
reshape wide unmarried , i(age) j(treat)

foreach var in "unmarried"{
gen `var'_diff = `var'1 - `var'0
gen ub = `var'_diff + 1.96* se
gen lb = `var'_diff - 1.96* se

}



tw sca unmarried_diff lb ub age ,ylabel(-4(2)12) xlabel(26(1)40) xtit("Age (1970-79 cohorts)") ytit("Difference (%)")  m(O D Dh) msiz(*0.5 *0.3 *0.3) ///
mc(black black black)  legend(order(1 3 2) lab(1 "Differnce") lab(3 "Upper bound (95% CI.)") lab(2 "Lower bound (95% CI.)") ///
size(small) pos(2) ring(0) col(1)) yline(0,  lp(dash) lc(gray))  
gr export "$path4/unmarried_age_han.pdf",replace 

restore


**** Figure 4(c) ****

preserve
keep if year_birth >= 1970 & year_birth <= 1979
keep if han == 0 
cap gen treat = 1 if prov == 11 | prov == 13 | prov == 21 | prov == 31 | prov == 32 | prov == 33 | prov == 35 ///
|prov == 41 | prov == 42 | prov == 43 |prov == 44 | prov == 45| prov == 46| prov == 53| prov == 64 | prov == 65
replace treat = 0 if mi(treat)

gen age_group = age > 30 & age < 36
replace age_group = 2 if age > 35

collapse unmarried [aw=aw], by( age_group treat )
reshape wide unmarried , i(age_group) j(treat)
gen dif = unmarried1- unmarried0 
sort age_group
loc i = string(dif, "%9.3f")
gen n = age_group
replace n = n - 2 if age_group == 1
sort n
loc i1 = string(dif, "%9.3f")
gen v = dif if age_group == 2
sort v
loc i2 = string(v, "%9.3f")
graph bar unmarried0 unmarried1  , ylabel(0(5)20) bargap(1) over(age_group, gap(100)  relabel(1 "Ages 26-30" 2 "Ages 31-35" 3 "Ages 36-40"))    legend(rows(2) lab(2 "Provinces w/ fines increase in 1989-1995") lab(1 "Provinces w/o fines increase in 1989-1995")) ytit("Unmarried (%)")    blabel(bar,format(%9.3f) ) text(19.5 12 "Difference = `i'") text(12 50 "Difference = `i1'") text(8 85 "Difference = `i2'") scheme(s1mono)
gr export "$path4/unmarried_agegrp_min.pdf",replace 

restore 

**** Figure 4(d) ****


preserve
keep if year_birth >= 1970 & year_birth <= 1979
keep if han == 0 
cap gen treat = 1 if prov == 11 | prov == 13 | prov == 21 | prov == 31 | prov == 32 | prov == 33 | prov == 35 ///
|prov == 41 | prov == 42 | prov == 43 |prov == 44 | prov == 45| prov == 46| prov == 53| prov == 64 | prov == 65
replace treat = 0 if mi(treat)
drop if treat == . 
levelsof age
qui:{
foreach x of numlist `r(levels)' {

ttest unmarried if age==`x' ,by(treat)
replace se=r(se) if age==`x'
}
}


collapse unmarried se[aw=aw], by( age treat )
reshape wide unmarried , i(age) j(treat)

foreach var in "unmarried"{
gen `var'_diff = `var'1 - `var'0
gen ub = `var'_diff + 1.96* se
gen lb = `var'_diff - 1.96* se

}

tw sca unmarried_diff lb ub age ,ylabel(-4(2)12) xlabel(26(1)40) xtit("Age (1970-79 cohorts)") ytit("Difference (%)")  m(O D Dh) msiz(*0.5 *0.3 *0.3) ///
mc(black black black)  legend(order(1 3 2) lab(1 "Differnce") lab(3 "Upper bound (95% CI.)") lab(2 "Lower bound (95% CI.)") ///
size(small) pos(2) ring(0) col(1)) yline(0,  lp(dash) lc(gray))  
gr export "$path4/unmarried_age_mino.pdf",replace 

restore



**** Appendix Figure A5(a) ****



preserve
keep if han == 1 & (((wave == 2005| wave == 2010) & age >= 36 & age <= 40)|((wave == 2005| wave == 2000) & age >= 31 & age <= 35))
gen treat = (wave == 2010& age >= 36 & age <= 40)|(wave == 2005& age >= 31 & age <= 35)
egen prov_treat = group(treat prov_hk year_birth male)
levelsof age
qui:{
foreach x of numlist `r(levels)' {

clttest unmarried if age==`x' ,by(treat) cl(prov_treat)
replace se=r(se) if age==`x'
}
}


collapse unmarried se[aw=aw], by( age treat )
reshape wide unmarried , i(age) j(treat)

foreach var in "unmarried"{
gen `var'_diff = `var'1 - `var'0
gen ub = `var'_diff + 1.96* se
gen lb = `var'_diff - 1.96* se

}


tw sca unmarried_diff lb ub age ,ylabel(-4(2)12) xlabel(31(1)40) xtit("Age") ytit("Difference (%)")  m(O D Dh) msiz(*0.5 *0.3 *0.3) ///
mc(dkgreen dkgreen dkgreen)  legend(order(1 3 2) lab(1 "Differnce") lab(3 "Upper bound (95% CI.)") lab(2 "Lower bound (95% CI.)") ///
size(small) pos(2) ring(0) col(1)) yline(0,  lp(dash) lc(blue))  
gr export "$path4/unmarried_age_coh.pdf",replace 

restore


**** Appendix Figure A5(b) ****


preserve
keep if han == 1 & (((wave == 2005| wave == 2010) & age >= 36 & age <= 40)|((wave == 2005| wave == 2000) & age >= 31 & age <= 35))
gen treat = (wave == 2010& age >= 36 & age <= 40)|(wave == 2005& age >= 31 & age <= 35)
gen age_group = age > 35

collapse unmarried [aw=aw], by( age_group treat )
reshape wide unmarried , i(age_group) j(treat)
gen dif = unmarried1- unmarried0 
sort age_group
loc i = string(dif, "%9.3f")
sort dif
loc i2 = string(dif, "%9.3f")
graph bar unmarried0 unmarried1     , ylabel(0(2)8) bargap(1) over(age_group, gap(100)  relabel(1 "Ages 31-35" 2 "Ages 36-40"))    legend(rows(2) lab(2 "Fully exposed cohorts (1970-74)") lab(1 "Partially exposed cohorts (1965-69)")) ytit("Unmarried (%)")    blabel(bar,format(%9.3f) ) text(7.5 20 "Difference = `i'") text(5 80 "Difference = `i2'")
gr export "$path4/unmarried_agegrp_coh.pdf",replace 

restore 
